<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="./validate.js"></script>
</head>
<body>
  
</body>
<script>
  function validNotEmpty(value) {
    const reg = /\S/; // 不为空
    return reg.test(value)
  }
  let data = {
    name: '',
    password: '1',
    password2: '1'
  }
  const validatePass = (value, callback) => {
    if (value !== data.password) {
      callback('两次密码不一致')
    } else {
      callback()
    }
  }
  let rules = {
    name: [
      { required: true, message: '用户名不能为空'}
    ],
    password: [
      { regular: validNotEmpty, message: '密码不能为空'}
    ],
    password2: [
      { regular: validNotEmpty, message: '确认密码不能为空'},
      { validator: validatePass}
    ]
  }
  
  // 验证表单
  validateRule(rules, data).then(res => {
    console.log(res)
  })
</script>
</html>